/*!
 * \file t__get_arr_line.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2016/03/31
 *
 */
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "frconfig.h"
#include "conntrack.h"
#include "frct_comm.h"

#include "apmtest_comm.h"

#define APM_BUFF_SIZE    128
#define APM_FILE_END     3
#define APM_LINE_SUCCESS 4

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}


extern int __get_arr_line(FILE *fp_in, char **pp_line, int i_getnotes);

static void __case1(void)
{
    FILE *fp = NULL;
    char *p_line = NULL;
    int i_ret = 0;

    i_ret = __get_arr_line(fp,&p_line, 0);

    CU_ASSERT_EQUAL(i_ret,APM_FRCONFIG_MEM_ERR);
    CU_ASSERT_PTR_NULL(p_line);

    return;
}

static void __case2(void)
{
    FILE *fp = NULL;
    char *p_line = NULL;
    int i_ret = 0;

    i_ret = __get_arr_line(fp,&p_line, 0);

    CU_ASSERT_EQUAL(i_ret,APM_FRCONFIG_MEM_ERR);
    CU_ASSERT_PTR_NULL(p_line);

    return;
}


static void __case3(void)
{
    FILE *fp = NULL;
    char *p_line = NULL;
    int i_ret = 0;

    fp = fopen("t_frconfig/t_get_arr_line/test1.txt","r");

    i_ret = __get_arr_line(fp,&p_line, 0);

    CU_ASSERT_PTR_NULL(p_line);
    CU_ASSERT_EQUAL(i_ret,APM_FILE_END);

    fclose(fp);

    return;
}

static void __case4(void)
{
    FILE *fp = NULL;
    char *p_line = NULL;
    int i_ret = 0;

    char *p_tar = (char *)"test test test test test test test test test test test test test test test test test test test test test test test test test t";

    fp = fopen("t_frconfig/t_get_arr_line/test2.txt","r");

    i_ret = __get_arr_line(fp,&p_line, 0);

    CU_ASSERT_STRING_EQUAL(p_line,p_tar);
    CU_ASSERT_EQUAL(i_ret,APM_LINE_SUCCESS);

    frfree(p_line);
    fclose(fp);

    return;
}

static void __case5(void)
{
    FILE *fp = NULL;
    char *p_line = NULL;
    int i_ret = 0;

    char *p_tar = (char *)"test test test test test test test test test test test test test test test test test test test test test test test test test te";

    fp = fopen("t_frconfig/t_get_arr_line/test3.txt","r");

    i_ret = __get_arr_line(fp,&p_line, 0);

    CU_ASSERT_STRING_EQUAL(p_line,p_tar);
    CU_ASSERT_EQUAL(i_ret,APM_LINE_SUCCESS);

    frfree(p_line);
    fclose(fp);

    return;
}

static void __case6(void)
{
    FILE *fp = NULL;
    char *p_line = NULL;
    int i_ret = 0;

    char *p_tar = (char *)"test test test test test test test test test test test test test test test test test test test test test test test test test tes";

    fp = fopen("t_frconfig/t_get_arr_line/test4.txt","r");

    i_ret = __get_arr_line(fp,&p_line, 0);

    CU_ASSERT_STRING_EQUAL(p_line,p_tar);
    CU_ASSERT_EQUAL(i_ret,APM_LINE_SUCCESS);

    frfree(p_line);
    fclose(fp);

    return;
}

int add_suite___get_arr_line(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frcomm __get_arr_line()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
    CU_add_test(pSuite, "case3", __case3);
    CU_add_test(pSuite, "case4", __case4);
    CU_add_test(pSuite, "case5", __case5);
    CU_add_test(pSuite, "case6", __case6);


    return FR_SUCC;
}
